Static Content Hosting Pattern

This document describes the Static Content Hosting Pattern example from the guide Cloud Design Patterns (see http://aka.ms/Cloud-Design-Patterns).

 


 

Before you start

 

Ensure that you have installed all of the software prerequisites. For details see the Release Notes.

 

The example demonstrates operational aspects of applications running in Windows Azure. Therefore, you will need to use the diagnostics tools in order to understand how the code sample works. You must ensure that the web and worker roles in the solution are configured to use the diagnostics mechanism. If not, you will not see the trace information generated by the example.

 


 

About the Example

 

This example shows how to reference static content from a publicly accessible storage service. The example contains a Windows Azure web role, which hosts a web application that references JavaScript files and images deployed to a Windows Azure storage account. This type of content is typically deployed to the storage account as part of the application deployment process. However, to simplify the example, these files are deployed to the storage account when the application starts up.

    The JavaScript and stylesheet content is referenced in the file App_Start\BundleConfig.cs by using a CDN URL. The image content is referenced in the file Views\Home\Index.cshtml. The URLs are generated by an HTML helper class implemented in the file StaticContentUrlHtmlHelper.cs.

    When running the application in release mode, you should note that these static resources are served out of the storage account, as opposed to being delivered by the application server.

 


 

Running the Example

 

You can run this example locally in the Visual Studio Windows Azure emulator. You can also run this example by deploying it to a Windows Azure Cloud Service.

 

  • Start Visual Studio using an account that has Administrator privileges ("Run as Administrator").
  • Open the solution you want to explore from the subfolders where you downloaded the examples.
  • Right-click on each role in Solution Explorer, select Properties, and ensure that the role is configured to generate diagnostic information.

  • If you want to run the example in the local Windows Azure emulator:
    • Press F5 in Visual Studio to start the example running.
    • Open the Windows Azure Compute Emulator UI from the icon in the notification area.
    • Select each role in turn and view the diagnostic information generated by Trace statements in the code.
  • If you want to run the example on Windows Azure:
    • Provision a Windows Azure Cloud Service.
    • Provision a Windows Azure storage account.
    • Update the file ServiceConfiguration.Cloud.cscfg by changing the value of the StaticContent.StorageConnectionString setting to the connection string for your storage account. You can do this in the Properties page for the role or by opening the file in the main Visual Studio window.
    • Deploy the application to your Cloud Service from Visual Studio.
    • Open the Server Explorer Window in Visual Studio and expand the Windows Azure entry.
    • Expand Cloud Services and then expand the entry for the solution you deployed.
    • Right-click each role instance and select View Diagnostics Data to see the diagnostic information generated by Trace statements in the code. This is written to the WADLogsTable in the Storage/Development/Tables section.